package org.japo.java.swing.igu;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.HeadlessException;
import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import org.japo.java.swing.listeners.GEA;

public class IGU extends JFrame {

    //Componentes 
    private JComboBox<String> cbbColor;

    //Valores predeterminados de Fuente
    Font f = new Font("Calibri", Font.BOLD, 16);

    JPanel pnlPrincipal = new JPanel();
  

    //Lista de colores
    String[] listaColores = {"Rojo", "Azul", "Amarillo", "Verde", "Cian", "Negro"};

    public IGU() {
        iniciarComponentes();

    }

    private void iniciarComponentes() {
//        pnlPrincipal.setLayout(null);

        //Gestor de eventos de accion
        GEA gea = new GEA(this);
        
        //Borde Combobox
        Border b = new BevelBorder(BevelBorder.RAISED);

        //Dimension del combobox
        Dimension dimCombo = new Dimension(300, 50);

        cbbColor = new JComboBox(listaColores);
        cbbColor.setPreferredSize(dimCombo);
        cbbColor.setFont(f);
        cbbColor.setBorder(b);
//        cbbColor.setLocation(100, 100);
        cbbColor.addActionListener(gea);
        pnlPrincipal.add(cbbColor);

        // Ventana principal
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setContentPane(pnlPrincipal);
        setResizable(false);
        setTitle("Lista de colores");
        setSize(400, 250);
        setLocationRelativeTo(null);

    }

    public void procesarColor(Object o) {
        String texto = (String) cbbColor.getSelectedItem();

        switch (texto) {
            case "Rojo":
                pnlPrincipal.setBackground(Color.RED);
                break;
            case "Amarillo":
                pnlPrincipal.setBackground(Color.YELLOW);
                break;
            case "Azul":
                pnlPrincipal.setBackground(Color.BLUE);
                break;
            case "Naranja":
                pnlPrincipal.setBackground(Color.ORANGE);
                break;
            default:
                pnlPrincipal.setBackground(Color.BLACK);

        }

    }
}
